<?php
/*
	我的下线
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page_setting');
	$levels=array();
	$return['levels']=$levels;
	
	$return['params']=array('page'=>1,'level'=>1);
	$return['psize']=20;
	$return['list']=array();
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname','snmid'));
	$member2=$this->get('member',array('mid'=>$_SESSION['uid']));
	$member['salefee']=$this->sum('order',array('uniacid'=>$_SESSION['uniacid'],'agent_id'=>$_SESSION['uid']),'carprice');
	$return['allagentnum']=pdo_count('core_members',array('fromuser'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$member=array_merge($member2,$member);
	$return['member']=$member;
	set_html('title',$return['setting']['tmydown']?:'我的团队');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$agent_ids=$_SESSION['uid'];
	if(!$agent_ids){
		exi('none');
	}
	//$agent_ids=$this->model('member')->getsysmids($_SESSION['uid']);
	//$agent_ids=$agent_ids?:array();
	//$agent_ids[]=$_SESSION['uid'];
	$params['fromuser']=$_SESSION['uid'];
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=pdo_getlist('core_members',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['member']=cfc('core')->member_show($item['id']);
		$member=pdo_get('jy_newcar_member',array('mid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));	
		if(!$member['id']){
			$this->model('member')->register(array('mid'=>$item['id']));
			$member=pdo_get('jy_newcar_member',array('mid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));	
		}
		$item['ispay']=pdo_count('jy_newcar_order',array('mid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
		$member['jihuotitle']=$item['ispay']>0?'已激活':'未激活';
		$item['member']=array_merge($item['member'],$member);
		$item['leveltitle']=$item['leveltitle']?:'默认等级';
		$item['agenttime']=date('Y-m-d H:i:s',$member['agenttime']);
		$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		$item['member_num']=pdo_count('core_members',array('fromuser'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
	}
	exi($list);
}
?>